//===-- DeclTypeRecordNodes.def - Serialization Metaprogramming -*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
/// \file
/// Defines macros used for metaprogramming with the serialized records
/// in the "decls-and-types" block of serialized ASTs.
///
/// You should define one of the following sets of macros:
/// - RECORD(Id)
/// - RECORD(Id) and RECORD_VAL(Id)
/// - Any of TYPE(Id), DECL(Id), PATTERN(Id)
//
//===----------------------------------------------------------------------===//

#ifndef RECORD
#define RECORD(Id)
#endif

#ifdef RECORD_VAL
#define DECLTYPERECORDNODES_HAS_RECORD_VAL 1
#else
#define DECLTYPERECORDNODES_HAS_RECORD_VAL 0
#define RECORD_VAL(Id, Value) RECORD(Id)
#endif

#ifndef TYPE
#define TYPE(Id) RECORD(Id##_TYPE)
#endif

#ifndef FIRST_TYPE
# if DECLTYPERECORDNODES_HAS_RECORD_VAL
#  define FIRST_TYPE(Id, Value) RECORD_VAL(Id##_TYPE, Value)
# else
#  define FIRST_TYPE(Id, Value) TYPE(Id)
# endif
#endif

#ifndef DECL
#define DECL(Id) RECORD(Id##_DECL)
#endif

#ifndef FIRST_DECL
# if DECLTYPERECORDNODES_HAS_RECORD_VAL
#  define FIRST_DECL(Id, Value) RECORD_VAL(Id##_DECL, Value)
# else
#  define FIRST_DECL(Id, Value) DECL(Id)
# endif
#endif

#ifndef PATTERN
#define PATTERN(Id) RECORD(Id##_PATTERN)
#endif

#ifndef FIRST_PATTERN
# if DECLTYPERECORDNODES_HAS_RECORD_VAL
#  define FIRST_PATTERN(Id, Value) RECORD_VAL(Id##_PATTERN, Value)
# else
#  define FIRST_PATTERN(Id, Value) PATTERN(Id)
# endif
#endif

#ifndef TRAILING_INFO
#define TRAILING_INFO(Id) RECORD(Id)
#endif

#ifndef OTHER
#define OTHER(Id, Value) RECORD_VAL(Id, Value)
#endif

// These IDs must \em not be renumbered or reordered without incrementing
// the version in ModuleFormat.h. Names, however, may change.
FIRST_TYPE(BUILTIN_ALIAS, 1)
TYPE(GENERIC_TYPE_PARAM)
TYPE(DEPENDENT_MEMBER)
TYPE(NOMINAL)
TYPE(TUPLE)
TRAILING_INFO(TUPLE_TYPE_ELT)
TYPE(FUNCTION)
TRAILING_INFO(FUNCTION_PARAM)
TYPE(METATYPE)
TYPE(PRIMARY_ARCHETYPE)
TYPE(OPENED_ARCHETYPE)
TYPE(OPAQUE_ARCHETYPE)
TYPE(PACK_ARCHETYPE)
TYPE(ELEMENT_ARCHETYPE)
TYPE(PROTOCOL_COMPOSITION)
TYPE(PARAMETERIZED_PROTOCOL)
TYPE(EXISTENTIAL)
TYPE(BOUND_GENERIC)

TYPE(GENERIC_FUNCTION)
TYPE(ARRAY_SLICE)
TYPE(DICTIONARY)
TYPE(REFERENCE_STORAGE)
TYPE(UNBOUND_GENERIC)
TYPE(OPTIONAL)
TYPE(VARIADIC_SEQUENCE)
TYPE(SIL_FUNCTION)
TYPE(DYNAMIC_SELF)
TYPE(EXISTENTIAL_METATYPE)
TYPE(SIL_BLOCK_STORAGE)
TYPE(SIL_MOVE_ONLY)
TYPE(SIL_BOX)
TYPE(NAME_ALIAS)

TYPE(PACK_EXPANSION)
TYPE(PACK_ELEMENT)
TYPE(PACK)
TYPE(SIL_PACK)

TYPE(ERROR)

TYPE(INTEGER)

TYPE(BUILTIN_FIXED_ARRAY)

FIRST_DECL(TYPE_ALIAS, 50)
DECL(GENERIC_TYPE_PARAM)
DECL(ASSOCIATED_TYPE)
DECL(STRUCT)
DECL(CONSTRUCTOR)
DECL(VAR)
DECL(PARAM)
DECL(FUNC)
DECL(OPAQUE_TYPE)
DECL(PATTERN_BINDING)
DECL(PROTOCOL)
TRAILING_INFO(DEFAULT_WITNESS_TABLE)
TRAILING_INFO(ASSOCIATED_TYPE)
TRAILING_INFO(PRIMARY_ASSOCIATED_TYPE)
DECL(PREFIX_OPERATOR)
DECL(POSTFIX_OPERATOR)
DECL(INFIX_OPERATOR)
DECL(CLASS)
DECL(ENUM)
DECL(ENUM_ELEMENT)
DECL(SUBSCRIPT)
DECL(EXTENSION)
DECL(DESTRUCTOR)
DECL(PRECEDENCE_GROUP)
DECL(ACCESSOR)
DECL(MACRO)

FIRST_PATTERN(PAREN, 80)
PATTERN(TUPLE)
TRAILING_INFO(TUPLE_PATTERN_ELT)
PATTERN(NAMED)
PATTERN(ANY)
PATTERN(TYPED)
PATTERN(VAR)

OTHER(PARAMETERLIST, 100)
// 211 is unused
OTHER(FOREIGN_ERROR_CONVENTION, 101)
OTHER(FOREIGN_ASYNC_CONVENTION, 102)
OTHER(XREF_TYPE_PATH_PIECE, 103)
OTHER(XREF_VALUE_PATH_PIECE, 104)
OTHER(XREF_EXTENSION_PATH_PIECE, 105)
OTHER(XREF_OPERATOR_OR_ACCESSOR_PATH_PIECE, 106)
OTHER(XREF_GENERIC_PARAM_PATH_PIECE, 107)
OTHER(XREF_INITIALIZER_PATH_PIECE, 108)

OTHER(ABSTRACT_CLOSURE_EXPR_CONTEXT, 109)
OTHER(PATTERN_BINDING_INITIALIZER_CONTEXT, 110)
OTHER(DEFAULT_ARGUMENT_INITIALIZER_CONTEXT, 111)
OTHER(TOP_LEVEL_CODE_DECL_CONTEXT, 112)

OTHER(GENERIC_PARAM_LIST, 120)
OTHER(GENERIC_SIGNATURE, 121)
OTHER(REQUIREMENT_SIGNATURE, 122)
OTHER(GENERIC_ENVIRONMENT, 123)
OTHER(BUILTIN_PROTOCOL_CONFORMANCE, 124)
OTHER(SIL_GENERIC_SIGNATURE, 125)
OTHER(SUBSTITUTION_MAP, 126)

OTHER(LOCAL_DISCRIMINATOR, 127)
OTHER(PRIVATE_DISCRIMINATOR, 128)
OTHER(FILENAME_FOR_PRIVATE, 129)

OTHER(DESERIALIZATION_SAFETY, 130)
OTHER(EXPANDED_MACRO_DEFINITION, 131)
OTHER(EXPANDED_MACRO_REPLACEMENTS, 132)

// 140 is unused; was ABSTRACT_PROTOCOL_CONFORMANCE
OTHER(NORMAL_PROTOCOL_CONFORMANCE, 141)
OTHER(SPECIALIZED_PROTOCOL_CONFORMANCE, 142)
OTHER(INHERITED_PROTOCOL_CONFORMANCE, 143)
OTHER(PACK_CONFORMANCE, 144)

OTHER(SIL_LAYOUT, 145)
// 146 is unused; was NORMAL_PROTOCOL_CONFORMANCE_ID
OTHER(PROTOCOL_CONFORMANCE_XREF, 147)
OTHER(MEMBERS, 148)
OTHER(XREF, 149)
OTHER(INLINABLE_BODY_TEXT, 150)
OTHER(SELF_PROTOCOL_CONFORMANCE, 151)

OTHER(XREF_OPAQUE_RETURN_TYPE_PATH_PIECE, 152)

OTHER(CLANG_TYPE, 153)

OTHER(DERIVATIVE_FUNCTION_CONFIGURATION, 154)

OTHER(ERROR_FLAG, 155)
OTHER(ABI_ONLY_COUNTERPART, 156)

TRAILING_INFO(CONDITIONAL_SUBSTITUTION)
TRAILING_INFO(CONDITIONAL_SUBSTITUTION_COND)

OTHER(LIFETIME_DEPENDENCE, 160)

TRAILING_INFO(INHERITED_PROTOCOLS)

#ifndef DECL_ATTR
#define DECL_ATTR(NAME, CLASS, OPTIONS, CODE) RECORD_VAL(CLASS##_DECL_ATTR, 180+CODE)
#endif
#include "swift/AST/DeclAttr.def"

#undef RECORD
#undef DECLTYPERECORDNODES_HAS_RECORD_VAL
#undef RECORD_VAL
#undef TYPE
#undef FIRST_TYPE
#undef DECL
#undef FIRST_DECL
#undef PATTERN
#undef FIRST_PATTERN
#undef TRAILING_INFO
#undef OTHER
